import { connect } from 'umi';
import { ResourcesContext } from './hooks/useResourcesContext';
import cls from 'classnames';
import './styles.less';
import { IResources } from './type';
import { ResouFirstStep } from './ResourceMenu';
import { useResourcesReducer } from './hooks';
import { ResouRootSteps } from './components';
import { ResourceRange } from './ResourceRange';

const ResourceController: React.FC<IResources> = ({ permissions }) => {
  const prefixCls = 'resour-'; //根部样式类名

  const { resourCurrent, commonDispatch } = useResourcesReducer(); //创建一个本模块的 reducer 保存某些状态改变,导致全局变化的数据
  return (
    <ResourcesContext.Provider
      value={{
        curRes: permissions, //权限参数
        prefixCls, // 根部样式类名
        resourCurrent, //总体步数, 区分 页面是 目录,菜单,权限,功能
        commonDispatch,
      }}
    >
      <div className={cls(prefixCls + 'row')}>
        <div className={cls(prefixCls + 'titleCol')}>
          <div className={cls(prefixCls + 'divBox')}>
            <ResouRootSteps />
          </div>
        </div>
        {resourCurrent == 0 ? <ResouFirstStep /> : <></>}
        {resourCurrent == 1 ? <ResourceRange resCurrKey={'resRange'} /> : <></>}
        {resourCurrent == 2 ? <ResourceRange resCurrKey={'resOpera'} /> : <></>}

        {/* {resourCurrent == 2 && <ResoucerOther />} */}
      </div>
    </ResourcesContext.Provider>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  permissions: baseLogin?.permissions,
  navTab,
}))(ResourceController);
